Vue.component('xcform_control_input_string', {
  template: '<el-form-item \
                :class="value.fieldjsonObj.xcform_prop_required.value?\'required\':\'\'"\
                :prop="value.fieldcode" \
                :rules="control.rules"\
                :label="value.fieldtitle">\
                <el-input v-model="value.value" show-word-limit clearable \
                    :placeholder="value.fieldjsonObj.xcform_base_placeholder.value" \
                    :maxlength="value.fieldjsonObj.xcform_prop_stringlength.value?value.fieldjsonObj.xcform_prop_stringlength.maxlength:null" \
                    :minlength="value.fieldjsonObj.xcform_prop_stringlength.value?value.fieldjsonObj.xcform_prop_stringlength.minlength:null" \
                    :disabled="control.disabled"></el-input> \
              </el-form-item>',
  props: {
    value: {
      type: Object,
    },
    disabled: {
      type: Boolean,
    },
    fieldfulljson: {
      type: Array,
    },
    xcform_id: {
      type: Number,
    }
  },
  data() {
    var validateFunction = (rule, value, callback) => {
      var that = this;
      that.value.value = (that.value.value) ? that.value.value : "";

      if (that.value.fieldjsonObj.xcform_prop_required.value) {
        if (that.value.value.length == 0) {
          return callback(new Error('不能为空'));
        }
      }

      if (that.value.fieldjsonObj.xcform_prop_stringlength.value) {
        if (that.value.value.length < that.value.fieldjsonObj.xcform_prop_stringlength.minlength) {
          return callback(new Error('输入内容长度必须大于' + that.value.fieldjsonObj.xcform_prop_stringlength.minlength));
        }
      }

      if (that.value.fieldjsonObj.xcform_prop_stringregex.value) {
        // var regex = new RegExp("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/");
        var regex = new RegExp(that.value.fieldjsonObj.xcform_prop_stringregex.pattern);
        if (!regex.test(that.value.value)) {
          return callback(new Error(that.value.fieldjsonObj.xcform_prop_stringregex.errormsg));
        }
      }
      return callback();
    };
    return {
      control: {
        disabled: false,
        rules: [{
          validator: validateFunction,
          trigger: 'blur'
        }]
      }
    };
  },
  created() {
    var that = this;
    that.control.disabled = that.disabled;
    if (that.value.fieldjsonObj.xcform_prop_readonly.value) {
      that.control.disabled = true;
    }
  },
  mounted() {
    var that = this;

  },
  methods: {}
});